package com.tidc.foundprovider7001.service;

import com.tidc.foundprovider7001.mapper.*;
import com.tidc.foundprovider7001.ov.UserOV;
import com.tidc.foundprovider7001.pojo.*;
import com.tidc.foundprovider7001.utiles.*;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.security.crypto.password.PasswordEncoder;

import org.springframework.social.connect.web.ProviderSignInUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.ServletWebRequest;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassNmae PasswordService
 * @Description TODO
 * @Author 14631
 **/
@Service
public class PasswordService {
	@Autowired
	public UserMapper userMapper;
	@Autowired
	ApplicationContextProvider ac;
	@Autowired
	EmailUtiles emailUtiles;
	@Autowired
	private PasswordEncoder passwordEncoder;
	@Autowired
	RegisterUtiles registerUtiles;

	public UserOV findStudentPassord(Student student, String code, HttpServletRequest req, UserOV userOV){

		return emailUtiles.email(student,code,req,userOV,"student");
	}
	public UserOV findteacherPassord(Teacher teacher, String code, HttpServletRequest req, UserOV userOV){
		return emailUtiles.email(teacher,code,req,userOV,"teacher");
	}
	public UserOV registerStudent(Student student, UserOV userOV){
		userOV = registerUtiles.register(student,null,userOV);
		if(userOV.getData()!=null){
			userMapper.addStudent((Student) userOV.getData());
		}
		return userOV;
	}
	public UserOV registerTeacher(Teacher teacher, UserOV userOV){
		userOV = registerUtiles.register(null,teacher,userOV);
		if(userOV.getData()!=null){
			userMapper.addTeacher((Teacher) userOV.getData());
		}
		return userOV;
	}


}
